intgetnum(){ int num = 0; char ch = getchar (); int isneg = 0;
while (! isdigit (ch)) { if (ch == '-') isneg = 1; ch = getchar (); } while (isdigit (ch)) num = (num << 3) + (num << 1) + ch - '0', ch = getchar ();
return isneg ? - num : num; }
intmain(){ while (~ (N = getnum ())) { M = getnum (); memset (f, 0, sizeof (f)); for (int i = 1; i <= N; i ++) { int vol = getnum (), value = getnum (); int b = 0; while (! (vol & 1)) vol >>= 1, b ++; for (int j = 1000; j >= vol; j --) f[b][j] = max (f[b][j], f[b][j - vol] + value); } int xm = M, maxb = 0; while (xm) xm >>= 1, maxb ++; for (int i = 0; i <= maxb; i ++) for (int j = 0; j <= 1000; j ++) f[i][j] = max (f[i][j], f[i][j - 1]); LL ans = 0; for (int i = 1; i <= maxb; i ++) for (int j = min (1000, M >> i); j >= 0; j --) // 注意此处上限是 min (100, M >> i),M >> i 保证不会将高位拿多了 for (int k = 0; k <= j; k ++) { f[i][j] = max (f[i][j], f[i][j - k] + f[i - 1][min ((k << 1) + ((M >> (i - 1)) & 1), 1000)]); ans = max (ans, f[i][j]); } printf ("%lld\n", ans); }